package vn.student.Adapter;
import static vn.student.util.CusorUtil.*;
import static vn.student.database.DBComman.*;
import vn.student.notificationforandroid.R;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class AdapterCanhan extends SimpleCursorAdapter {

    LayoutInflater inflater;
    Cursor c;
    int layout;
    public AdapterCanhan(Context context, int layout, Cursor c, String[] from,
	    int[] to) {
	super(context, layout, c, from, to);
	inflater= LayoutInflater.from(context);
	this.c=c;
	this.layout=layout;
    }
    public void setC(Cursor c) {
	this.c = c;
	this.notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {	
	View v=convertView;
	c.moveToPosition(position);
	LayoutHorder layoutHorder;
	if(v==null)
	{
	    v=inflater.inflate(layout, null);
	    layoutHorder= new LayoutHorder();
	    layoutHorder.mTxtConent = (TextView)v.findViewById(R.id.row_canhan_context);
	    layoutHorder.mTxtTile = (TextView)v.findViewById(R.id.row_canhan_title);
	    layoutHorder.mTxtTime = (TextView)v.findViewById(R.id.row_canhan_time);
	    v.setTag(layoutHorder);
	}
	else
	{
	    layoutHorder=(LayoutHorder)v.getTag();
	}
	layoutHorder.mTxtConent.setText(getCusorStr(c, CONTENT));
	layoutHorder.mTxtTime.setText(getCusorStr(c, TIME));
	layoutHorder.mTxtTile.setText(getCusorStr(c,TITLE));
        return v;
    }
    static class LayoutHorder
    {
	TextView mTxtTile,mTxtTime,mTxtConent;
    }

}
